<?php
namespace app\api\service;
use think\Cache;
use think\Controller;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/26 0026
 * Time: 15:40
 */

class Base extends Controller {

    /**
     * 清除缓存
     */
    public static function clear_cache() {
        Cache::clear();
    }

    /**
     * 获取系统配置信息
     * @return array
     */
    public static function get_system_info() {
        $data = config('system');
        return api_return(200, $data);
    }

    /**
     * 获取消息和购物车数量
     * @param $param
     * @return array
     */
    public static function get_count_num($param) {
        try {
            if (!isset($param['member_id']) || !$param['member_id']) {
                $data = [
                    'count' => 0,
                    'cart_count' => 0,
                    'message_count' => 0
                ];
            } else {
                $cart_num = model('cart')->where('member_id', $param['member_id'])->count();

                $data = [
                    'count_num' => $cart_num,
                    'cart_num' => $cart_num,
                    'message_num' => 0
                ];
            }
            return api_return(200, $data);
        } catch (\Exception $e) {
            return api_return(0, [], $e->getMessage());
        }

    }
}